package com.shanghaionstar.mro.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;

import com.onstar.cn.weight.CustomButton;
import com.onstar.cn.weight.CustomImageView;
import com.shanghaionstar.R;
import com.shanghaionstar.enumtype.DealerBrandType;
import com.shanghaionstar.mro.MrOActivity;

public class MrOFootLayout extends RelativeLayout implements View.OnClickListener {
    private View view;
    private CustomImageView mro_left;
    private CustomImageView mro_right;
    private RelativeLayout mro_bottom_xiaoo;
    private CustomImageView mro_bottom_xiaoo_head;
    private CustomImageView mro_bottom_xiaoo_eye;
    private CustomButton mro_confirm;
    private MrOActivity mrOActivity;
    private DealerBrandType brandType = DealerBrandType.DEFAULT;
    private boolean isFeedback;

    public MrOFootLayout(Context context) {
        super(context);
        initView();
    }

    public MrOFootLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView();
    }

    private void initView() {
        view = inflate(getContext(), R.layout.mro_footview, this);
        mro_left = (CustomImageView) view.findViewById(R.id.mro_left);
        mro_right = (CustomImageView) view.findViewById(R.id.mro_right);
        mro_bottom_xiaoo = (RelativeLayout) view.findViewById(R.id.mro_bottom_xiaoo);
        mro_bottom_xiaoo_head = (CustomImageView) view.findViewById(R.id.mro_bottom_xiaoo_head);
        mro_bottom_xiaoo_eye = (CustomImageView) view.findViewById(R.id.mro_bottom_xiaoo_eye);
        mro_confirm = (CustomButton) view.findViewById(R.id.mro_bottom_confirm);
        mro_left.setOnClickListener(this);
        mro_right.setOnClickListener(this);
        mro_bottom_xiaoo.setOnClickListener(this);
        mro_confirm.setOnClickListener(this);
        mrOActivity = (MrOActivity) getContext();
    }

    public void showMrO(boolean isShow) {
        if (isShow) {
            mro_bottom_xiaoo.setVisibility(View.VISIBLE);
        } else {
            mro_bottom_xiaoo.setVisibility(View.GONE);
        }
    }

    public void showConfirm(boolean isShow) {
        if (isShow) {
            mro_confirm.setVisibility(View.VISIBLE);
        } else {
            mro_confirm.setVisibility(View.GONE);
        }
    }

    public void changeBrand(DealerBrandType dealerBrandType) {
        if (brandType == dealerBrandType)
            return;
        brandType = dealerBrandType;
        switch (dealerBrandType) {
            case DEFAULT:
                mro_bottom_xiaoo_head.setImageResource(R.drawable.mro_obotton_default);
                break;
            case BUICK:
                mro_bottom_xiaoo_head.setImageResource(R.drawable.mro_obotton_buick);
                break;
            case CHEVROLET:
                mro_bottom_xiaoo_head.setImageResource(R.drawable.mro_obotton_chevrolet);
                break;
            case CADILLAC:
                mro_bottom_xiaoo_head.setImageResource(R.drawable.mro_obotton_cadillac);
                break;
            case WTK:
                mro_bottom_xiaoo_head.setImageResource(R.drawable.mro_obotton_wtk);
                break;
        }
    }

    public void setIsFeedback(boolean isFeedback) {
        this.isFeedback = isFeedback;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.mro_left:
                mrOActivity.onBackPressed();
                break;
            case R.id.mro_right:
                mrOActivity.gotoHelp();
                break;
            case R.id.mro_bottom_xiaoo:
                mrOActivity.listen(isFeedback);
                break;
            case R.id.mro_bottom_confirm:
                mrOActivity.onConfirmButtonClick();
                mrOActivity.onBackPressed();
                break;
        }
    }

    public interface OnFootViewConfirmButtonListener {
        void onConfirmButtonClick();
    }
}
